// Drummer Port Form
// by Andrea Bianchi
// drummer.alsoplantsfly.com


/*
Copyright (C) 2009, Andrea Bianchi

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/


import javax.swing.SpinnerNumberModel;


public class PortForm extends javax.swing.JFrame {
    

    public PortForm() {
        initComponents();
    }
    
                    
    private void initComponents() {
        cancBut = new javax.swing.JButton();
        okBut = new javax.swing.JButton();
        spinner = new javax.swing.JSpinner();
        label = new javax.swing.JLabel();

        getContentPane().setLayout(null);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Port Form");
        cancBut.setText("Cancel");
        cancBut.setNextFocusableComponent(okBut);
        cancBut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancButActionPerformed(evt);
            }
        });

        getContentPane().add(cancBut);
        cancBut.setBounds(20, 70, 86, 29);

        okBut.setText("OK");
        okBut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButActionPerformed(evt);
            }
        });

        getContentPane().add(okBut);
        okBut.setBounds(100, 70, 75, 29);

        spinner.setModel(new javax.swing.SpinnerNumberModel(6000, 6000, 10000, 1) );
        spinner.setToolTipText("Port Number");
        spinner.setNextFocusableComponent(cancBut);
        getContentPane().add(spinner);
        spinner.setBounds(60, 40, 80, 28);

        label.setText("Choose a valid Port Number");
        getContentPane().add(label);
        label.setBounds(10, 10, 190, 20);
      
        setBounds(mouseX,mouseY,200,130);
        setVisible(true);
       
    }                      

    private void cancButActionPerformed(java.awt.event.ActionEvent evt) {                                        
      setVisible(false);
    }                                       

    private void okButActionPerformed(java.awt.event.ActionEvent evt) {                                      
      try{    
        SpinnerNumberModel model = (SpinnerNumberModel)spinner.getModel();
        int portNumber = model.getNumber().intValue();
        netw.startNetwork(portNumber);
      }
      catch (Exception e){
        return;
      }
      
      setVisible(false);
    }                                     
    


                      
    private javax.swing.JButton cancBut;
    private javax.swing.JLabel label;
    private javax.swing.JButton okBut;
    private javax.swing.JSpinner spinner;               
}

